$(function() {
	setHeight("#sel_height_min", 140);
	setHeight("#sel_height_max", 140);

	setAge('#sel_age_min', 18);
	setAge('#sel_age_max', 18);

	for (var i = 0; i < 6; i++) {
		judgeDefaultData($("#sel_con_edu"), i);
		judgeDefaultData($("#sel_con_income"), i);
	}

	$("#sel_age_min").change(function() {
		var minAge = parseInt($("#sel_age_min").val());
		$("#sel_age_max").empty();
		setAge("#sel_age_max", minAge);
	});

	$("#sel_height_min").change(function() {
		var minHeight = parseInt($("#sel_height_min").val());
		$("#sel_height_max").empty();
		setHeight("#sel_height_max", minHeight);
	});

	$('#saveConBtn').click(function() {
		$.post("userAjax_updatePersonalsCondition", {
			"personalsCondition.address" : $("#sel_con_province").val() + "-" + $("#sel_con_city").val(),
			"personalsCondition.minAge" : $("#sel_age_min").val(),
			"personalsCondition.maxAge" : $("#sel_age_max").val(),
			"personalsCondition.minHeight" : $("#sel_height_min").val(),
			"personalsCondition.maxHeight" : $("#sel_height_max").val(),
			"personalsCondition.education" : $("#sel_con_edu").val(),
			"personalsCondition.income" : $("#sel_con_income").val(),
		}, function(data) {
			if (data != "true") {
				art.dialog.alert('发生未知错误！！！').time(2);
			} else {
				art.dialog.alert('保存成功！！').time(2);
			}
		});
		return false;
	});

	var apartments;
	if ($("#sel_con_province").attr('defaultData') != "") {
		apartments = $("#sel_con_province").attr('defaultData').split("-");
	} else {
		apartments = ["不限制", "不限制"];
	}
	var s1 = ["sel_con_province", "sel_con_city"];
	_init_area(s1, apartments);

});

function setAge(ageId, minAge) {
	$(ageId).append("<option class='selectList' value='0'>不限制</option>");
	for (var i = minAge; i <= 80; i += 2) {
		var s = "";
		if ($(ageId).attr('defaultData') == i) {
			s = "<option class='selectList' value='" + i + "' selected='true'>" + i + "岁</option>";
		} else {
			s = "<option class='selectList' value='" + i + "'>" + i + "岁</option>";
		}
		$(ageId).append(s);
	}
}

function setHeight(heightId, minHeight) {
	$(heightId).append("<option class='selectList' value='0'>不限制</option>");
	for (var i = minHeight; i <= 200; i += 5) {
		var s = "";
		if ($(heightId).attr('defaultData') == i) {
			s = "<option class='selectList' value='" + i + "' selected='true'>" + i + "厘米</option>";
		} else {
			s = "<option class='selectList' value='" + i + "'>" + i + "厘米</option>";
		}
		$(heightId).append(s);
	}
}

function judgeDefaultData(defaultData, i) {//默认选择
	if (defaultData.attr('defaultData') == i) {
		defaultData.children().eq(i).attr('selected', 'true');
	}
}

